package mail;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhjr
 * @date 2021/4/12 11:37
 * @desc :
 */
public class QRcode {
    public static void main(String[] args) {
        Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        BitMatrix bitMatrix = null;// 生成矩阵
        try {
            bitMatrix = new MultiFormatWriter().encode("gfsgfs",
                    BarcodeFormat.QR_CODE, 300, 300, hints);
        } catch (Exception e) {
            e.printStackTrace();
        }
        BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            ImageIO.write(image, "png", os);
            File file = new File("E:\\aa");
            FileOutputStream fos = null;
            fos = new FileOutputStream(file);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
